package com.op.teachingliteapp.common;

import android.app.Application;
import android.content.Context;

import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
import com.op.teachingliteapp.util.http.VolleySingleton;

public class BaseApp extends Application {

	private static Context mContext;

	@Override
	public void onCreate() {
		super.onCreate();
		initImageLoader(getApplicationContext());
		mContext = this;
		VolleySingleton.getInstance().init(getAppContext());
	}

	/**
	 * 返回全局的context
	 * 
	 * @return
	 */
	public static Context getAppContext() {
		return mContext;
	}

	public static void initImageLoader(Context context) {
		ImageLoaderConfiguration.Builder config = new ImageLoaderConfiguration.Builder(context);
		config.threadPriority(Thread.NORM_PRIORITY - 2);
		config.denyCacheImageMultipleSizesInMemory();
		config.diskCacheFileNameGenerator(new Md5FileNameGenerator());
		config.diskCacheSize(50 * 1024 * 1024);
		config.tasksProcessingOrder(QueueProcessingType.LIFO);
		config.writeDebugLogs();

		ImageLoader.getInstance().init(config.build());
	}

}
